home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr28 / sc3x02.zip / NWSYS.C < prev    next >
Text File  |  1993-03-01  |  3KB  |  88 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      nwsys.c                                               ║
  4. //   ║ abstract:    This module shows how to make 3.x system calls using  ║
  5. //   ║              the F2 Shell Interface.  Obviously, it requires the   ║
  6. //   ║              NetWare Shell.                                        ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Borland C 3.0                                         ║
  10. //   ║                                                                    ║
  11. //   ║  This software is provided as is and carries no warranty           ║
  12. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  13. //   ║  warranties of merchantability, title and fitness for a particular ║
  14. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  15. //   ║  your requirements or that the software is without defect or error ║
  16. //   ║  or that operation of the software will be uninterrupted.  You are ║
  17. //   ║  using the software at your risk.  The software is not a product   ║
  18. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  19. //   ╚════════════════════════════════════════════════════════════════════╝
  20.  
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <dos.h>
  24. #include <fcntl.h>
  25. #include <sys/stat.h>
  26.  
  27. #include "nwsys.h"
  28.  
  29. //
  30. //  These are some helper routines we need to make system calls.  These
  31. //  are probably better off written in assembly, but I didn't want to tie
  32. //  this to a specific compiler.  Call Developer Support if you want the
  33. //  assembly version...
  34. //
  35.  
  36. DWORD   DWordSwap( DWORD input )
  37. {
  38.     struct _hilo{
  39.         WORD    lwlb:8;     // low word, low byte
  40.         WORD    lwhb:8;     // low word, hi  byte
  41.         WORD    hwlb:8;     // hi  word, low byte
  42.         WORD    hwhb:8;     // hi  word, hi  byte
  43.     }data;
  44.  
  45.     data = *(struct _hilo *)&input; // assign it to data
  46.  
  47.     return ((long)data.lwlb << 24) | ((long)data.lwhb << 16) |
  48.            ((long)data.hwlb << 8)  |  (long)data.hwhb;
  49. }
  50.  
  51. WORD    WordSwap( WORD input )
  52. {
  53.     struct _hilo{
  54.         WORD    lwlb:8;     // low byte
  55.         WORD    lwhb:8;     // hi  byte
  56.     }data;
  57.  
  58.     data = *(struct _hilo *)&input; // assign it to data
  59.  
  60.     return data.lwlb << 8 | data.lwhb;
  61. }
  62.  
  63. WORD    NWSystemCall(BYTE func,             // function code
  64.              void far * req,        // request buffer
  65.              WORD reqLen,           // request length
  66.              void far *rep,         // reply buffer
  67.              WORD repLen)           // reply length
  68. {
  69.     union   REGS    regs;
  70.     struct  SREGS   sregs;
  71.  
  72.     segread(&sregs);
  73.  
  74.     regs.x.ax = 0xf200 | func;      // AX = F2nn 'nn' is function code
  75.     regs.x.cx = reqLen;             // CX = request buffer length
  76.     regs.x.dx = repLen;             // DX = reply buffer length
  77.     regs.x.si = FP_OFF(req);        // SI = request buffer offset
  78.     regs.x.di = FP_OFF(rep);        // DI = reply buffer offset
  79.  
  80.     sregs.ds = FP_SEG(req);         // DS = request buffer segment
  81.     sregs.es = FP_SEG(rep);         // ES = reply buffer segment
  82.  
  83.     intdosx(®s,®s,&sregs);    // do the Int 21
  84.  
  85.     return (WORD)regs.h.al;         // return code is in AL
  86. }
  87.  
  88.